package org.example.seata.common.security.util;

import lombok.extern.slf4j.Slf4j;
import org.example.seata.bs.api.entity.account.AccountAuth;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;

import java.util.List;

/**
 * @author hzq
 * @date 2021/12/9 16:56
 */
@Slf4j
public class MenuFacUtil {

    /**
     * 模拟菜单
     * 菜单根据客户端设置
     *
     * @return 菜单列表
     */
    public static List<GrantedAuthority> getUserMenu(AccountAuth auth) {

        log.info("获取用户【{}】权限", auth.getUnionId());

        String clientId = SecurityUtil.getClientId();

        // todo 查询各个端的用户权限

        if ("pcSide".equals(clientId)) {
            return AuthorityUtils.createAuthorityList("pcSide" + auth.getAccountId());
        }

        if ("mobileSide".equals(clientId)) {
            return AuthorityUtils.createAuthorityList("mobileSide" + auth.getAccountId());
        }

        return AuthorityUtils.NO_AUTHORITIES;
    }


}
